<?php
session_start();
require("../bin/common.php");
checkSess();
checkInstall();

//Generate URL
function genURL($x,$y) {
	//Find Address
	
	//Check if want to use full url or not
	if ($y == "full") {
		$docurl = "http://";
		$docurl .= $_SERVER['SERVER_NAME'];
	}
	
	//Find Path
	$docpath = $_SERVER['PHP_SELF'];
	
	//Explode all slashes
	$docexp = explode("/",$docpath);
	
	//Find Length of File Name (Last Value in Exploded Array)
	$doclen = strlen(end($docexp));
	
	//Add length of setup/ to doclen (lazy way)
	$doclen = $doclen + 6;
	
	//URL Of Document without file name
	$doclean = substr($docpath, 0, -$doclen);
	
	//Return URL
	//Add $docurl before $doclean for full URL.
	return "".$docurl . $doclean."patch/".$x."";	
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Generate Neoncube.ini - Vanadium Patch Mananger</title>
<link href="../lib/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../lib/script.js"></script>
</head>
<body onload="fixSize()" onresize="fixSize()">

<div class="container" id="container">

	<!-- Header -->
	<div class="top">
	Vanadium Patch Manager

	<?php
	dispLogin();
	?>
	</div>
    
	<!-- Left Hand Panel -->
	<div class="left">
		<br /><span class="nav_option"><img src="../lib/gfx/icon_home.gif" width="15" height="15" alt="Home" /> <a href="../home/">Home</a></span><br /><br />
		<span class="nav_tab_option"><img src="../lib/gfx/icon_add.gif" width="12" height="12" alt="Add" /> <a href="../addpatch/">Add Patch</a></span><br /><br />
		<span class="nav_tab_option"><img src="../lib/gfx/icon_edit.gif" width="13" height="16" alt="Edit" /> <a href="../patch/changelog.php">View Changelog</a></span><br /><br />
		<span class="nav_tab_option"><img src="../lib/gfx/icon_edit.gif" width="13" height="16" alt="Edit" /> <a href="../editpatch/">Edit Patch Home</a></span><br /><br />
		<span class="nav_tab_option"><img src="../lib/gfx/icon_setup.gif" width="14" height="16" alt="Setup" /> <a href="../setup/">Setup</a></span><br /><br />
        <span class="nav_tab_tab_option"><img src="../lib/gfx/icon_edit.gif" width="13" height="16" alt="Edit" /> <a href="../setup/neoncube.php">Neoncube.ini</a></span><br /><br />
        <span class="nav_tab_tab_option"><img src="../lib/gfx/icon_account.gif" width="14" height="14" alt="Accounts" /> <a href="../setup/accounts.php">Accounts</a></span><br /><br />
        <span class="nav_tab_tab_option"><img src="../lib/gfx/icon_cp.gif" width="16" height="16" alt="Control Panel" /> <a href="../setup/cpanel.php">Control Panel</a></span>
	</div>
    
	<!-- Body Content Container -->
	<div class="content_container" id="content_container">
    
		<!--Content Title -->
		<div class="content_title">
			Setup - Generate Neoncube.ini
		</div>
        
		<!--Content Body -->
	  <div class="content_body">            
        <?php
		if (isset($_POST['svr_name']) and isset($_POST['exec'])) {
			$fp = fopen("../lib/neoncube.ini","w");
											
			if(!$fp) {
				echo 'Error: Cannot open neoncube.ini file.';
				exit;
			}
			
			$skin = $_POST['skin'];
			$grf = $_POST['grf'];
			$register = $_POST['registration'];
			
			if ($skin == "") {
				$skin = "skin_default";
			}
			
			if ($grf == "") {
				$grf = "updates.grf";
			}
			
			if ($register == "") {
				$register = $_SERVER['SERVER_NAME'];
			}
			
			$content = "[server]\n\nserver_name = ".$_POST['svr_name']."\nnotice_url = ".genURL("notice.html","full")."\npatch_site = ".$_SERVER['SERVER_NAME']."\npatch_port = 80\npatch_list = ".genURL("patchlist.txt","")."\npatch_folder = ".genURL("","")."\n\nexecutable = ".$_POST['exec']."\nregistration_link = ".$register."\n\nskin = ".$skin."\n\ngrf_file = ".$grf."\nBackup_GRF = 1\nstartup_option = 3\n\n[general]\n\n;debug_mode = 0\n;archive_passphrase =";
		
		fwrite($fp, $content);
		
		fclose($fp);
		
		echo "Your neoncube.ini file has been successfully generated. You may download it here:<br /><br />
          <img src=\"../lib/gfx/icon_download.gif\" width=\"16\" height=\"16\" alt=\"Neoncube\" /> <a href=\"../bin/download.php?file=neoncube.ini\" target=\"_self\">Download Neoncube.ini</a>";
		}
		else {
			echo "Something went wrong, it seems you may have tried to view thsi page without posting the variables first.<br /><br /><a href=\"neoncube.php\">Click here to return to neoncube.php</a>";
		}
		?>
        </div>
    
	<!--End Content Container-->
	</div>
    
	<!--Footer -->
	<div class="footer">
		Vanadium Patch Manager, A Neoncube Patch Modification.<br />
		GNU General Public License v3 - 2010<br />
		http://code.google.com/p/vanadiumpatch/
	</div>
<!--End Container-->
</div>
</body>
</html>